#include <iostream>
#include "Balle.h"

#define HAUTEUR_FENETRE 600
#define LONGUEUR_FENETRE 800
#define TAILLEBALLE 25
#define HAUT 0
#define BAS 1
#define DROITE 2
#define GAUCHE 3

#define COLLISIONHAUT 2
#define COLLISIONDROITE 1
#define COLLISIONBAS 3
#define COLLISIONGAUCHE 4

using namespace std;

Balle::Balle() : x(400), y(300)
{
    speed=3.0;
    directionVerticale=BAS;
    directionHorizontale=DROITE;
    shape = new RectangleShape();
    shape->setSize(sf::Vector2f(TAILLEBALLE, TAILLEBALLE));
    shape->setOutlineColor(sf::Color::Red);
    shape->setPosition(x, y);
}

void Balle::move()
{
    if(directionVerticale == HAUT) y-=speed;
    else y+=speed;

    if(directionHorizontale == GAUCHE) x-=speed;
    else x+=speed;

    shape->setPosition(x, y);
}


int Balle::checkCollision()
{
    if(x+speed >= LONGUEUR_FENETRE)
        return COLLISIONDROITE;
    else if(x-speed <= 0)
        return COLLISIONGAUCHE;
    else if(directionVerticale == HAUT && y-1 <= 0)
        return COLLISIONHAUT;
    else if(directionVerticale == BAS && y+1+TAILLEBALLE >= HAUTEUR_FENETRE)
        return COLLISIONBAS;

    return -1;
}

void Balle::changeDirectionVerticale()
{
    if(directionVerticale == HAUT) directionVerticale=BAS;
    else directionVerticale=HAUT;
}

void Balle::changeDirectionHorizontale()
{
    if(directionHorizontale == DROITE) directionHorizontale=GAUCHE;
    else directionHorizontale=DROITE;

}

void Balle::update()
{
    shape->setPosition(x, y);
}

int Balle::getX(){return x;}
int Balle::getY(){return y;}
float Balle::getSpeed(){return speed;}
int Balle::getDirectionVerticale(){return directionVerticale;}
int Balle::getDirectionHorizontale(){return directionHorizontale;}
RectangleShape* Balle::getShape(){return shape;}
void Balle::setDirectionVerticale(int dir){directionVerticale=dir;}
void Balle::setDirectionHorizontale(int dir){directionHorizontale=dir;}


void Balle::setX(int x){this->x=x;}
void Balle::setY(int y){this->y=y;}
void Balle::setSpeed(float speed){this->speed=speed;}
void Balle::accelerer(float acceleration){speed+=acceleration;}

